package passenger;
import java.util.ArrayList;
import java.util.List;
import route.Route_1;
import route.Route_2;
import route.Route_3;
import route.Route_4;
import route.Route_5;

public class pass {
//	public static boolean []year=new boolean[3];//baby:child:adult
//	public static boolean []card=new boolean[3];//all_life:normal:star
//	public static boolean []seat=new boolean[4];//head,work,very,normal
//	public static boolean []baggage=new boolean[2];//normal,special(删除)
//	public static boolean []route=new boolean[6];//in:0:1:2:3:4:5
	public static int []count= {0,0,0,0,0,0,0};//count:0:1:2:3:4:5:6
	public static int []Tot_weight={0,0,0,0,0,0,0};//类型不同行李的总重量
	public static List<List<Integer>>buggage= new ArrayList<>();
	public static int F_price=0;
	public static int S_weight=0;
	public static int free_weight=0;
	public static int special_price=0;
	public static int normal_price=0;
	public static int []col= {0,0,0,0};
	public static void main(String args[])
	{
		pass p=new pass();
		int po[][]= {{0,100,40,30,20},{0,100,20,20,21},{0,100,40,30,23}};
		int m=p.ReturnResult(2,1,2,4,"2000",po);
		System.out.println(m);
	}
	public boolean init(int a,int b,int c,int e,String fly_price,int bug[][])
	{
		col[0]=a;
		col[1]=b;
		col[2]=c;
		col[3]=e;
		try {
			F_price=Integer.parseInt(fly_price);//获得机票价格
			}catch (NumberFormatException e1) {
				return false;
		 }
		buggage.clear();
		for(int i=0;i<bug.length;i++)
		{
			List<Integer>ht=new ArrayList<>();
			for(int j=0;j<bug[i].length;j++)
			{
				ht.add(bug[i][j]);
			}
			buggage.add(ht);
		}
		for(int i=0;i<7;i++)
		{
			count[i]=0;
			Tot_weight[i]=0;
		}
		free_weight=0;
		S_weight=0;
		special_price=0;
		normal_price=0;
		for(int i=0;i<buggage.size();i++)
		{
			count[buggage.get(i).get(0)]++;
			Tot_weight[buggage.get(i).get(0)]+=buggage.get(i).get(4);
		}//获得不同类型行李的总重量
		return true;
	}
	
	public int ReturnResult(int a,int b,int c,int e,String fly_price,int bug[][])
	{
		boolean km=init(a,b,c,e,fly_price,bug);
		if(km==false)
		{
			return -1;
		}
		boolean kt=cal_Special_price();
		if(kt==false)
		{
			return -1;
		}
		if(col[3]==0)
		{
			boolean nt=cal_Normal_price();
			if(nt==false)
			{
				return -1;
			}
			else
			{
				return special_price+normal_price;
			}
		}
		else if(col[3]==1)
		{
			Route_1 dog=new Route_1();
			dog.init(buggage,col);
			if(dog.calculate()==false)
			{
				return -1;
			}
			else
			{
				return dog.extra_money+special_price;
			}		
		}
		else if(col[3]==2)
		{
			Route_2 dog=new Route_2();
			dog.init(buggage,col);
			if(dog.calculate()==false)
			{
				return -1;
			}
			else
			{
				return dog.extra_money+special_price;
			}		
		}
		else if(col[3]==3)
		{
			Route_3 dog=new Route_3();
			dog.init(buggage,col);
			if(dog.calculate()==false)
			{
				return -1;
			}
			else
			{
				return dog.extra_money+special_price;
			}		
		}
		else if(col[3]==4)
		{
			Route_4 dog=new Route_4();
			dog.init(buggage,col);
			if(dog.calculate()==false)
			{
				return -1;
			}
			else
			{
				return dog.extra_money+special_price;
			}		
		}
		else if(col[3]==5)
		{
			Route_5 dog=new Route_5();
			dog.init(buggage,col);
			if(dog.calculate()==false)
			{
				return -1;
			}
			else
			{
				return dog.extra_money+special_price;
			}		
		}
		return -1;
	}
	public boolean cal_Normal_price()//国内计重
	{
		for(int i=0;i<buggage.size();i++)
		{
			if(buggage.get(i).get(0).equals(0))
			{
				List<Integer>tmp=buggage.get(i);
				if(tmp.get(4)>32||tmp.get(1)>100||tmp.get(2)>60||tmp.get(3)>40||tmp.get(4)<2||(tmp.get(1)+tmp.get(2)+tmp.get(3))<60)
				{
					return false;
				}//不符合要求
			}
		}
		int [][]grid= {{40,30,20,20},{40,30,20,20},{10,10,10,10}};
		free_weight=grid[col[0]][col[2]];
		int []extra= {30,20,20};
		free_weight+=extra[col[1]];
		if(Tot_weight[0]-free_weight>0)
		{
			normal_price=(int) Math.round((Tot_weight[0]-free_weight)*0.015*F_price);
		}
		return true;
	}
	public boolean cal_Special_price()//特殊行李运费
	{
		int [][]grid= {{0,0,0,0},{1300,1300,2600,3900},{2600,2600,3900,5200},{490,490,3900,-1},{1300,1300,2600,-1},
				{1300,-1,-1,-1}};//2-5-23-32-45
		int index=-1;
		for(int j=0;j<buggage.size();j++)
		{ 
			if(buggage.get(j).get(0)==6)//动物
			{
				if(buggage.get(j).get(4)>=2&&buggage.get(j).get(4)<=8)
				{
					special_price+=3900;
				}
				else if(buggage.get(j).get(4)>8&&buggage.get(j).get(4)<=23)
				{
					special_price+=5200;
				}
				else if(buggage.get(j).get(4)>23&&buggage.get(j).get(4)<=32)
				{
					special_price+=7800;
				}
				else
				{
					return false;
				}
			}
			else if(buggage.get(j).get(0)>0&&buggage.get(j).get(0)<=5)//其余特殊物品
			{
				if(buggage.get(j).get(4)>=2&&buggage.get(j).get(4)<=5)
				{
					index=0;
				}
				else if(buggage.get(j).get(4)>5&&buggage.get(j).get(4)<=23)
				{
					index=1;
				}
				else if(buggage.get(j).get(4)>23&&buggage.get(j).get(4)<=32)
				{
					index=2;
				}
				else if(buggage.get(j).get(4)>32&&buggage.get(j).get(4)<=45)
				{
					index=3;
				}
				else
				{
					return false;
				}
				if(grid[buggage.get(j).get(0)][index]!=-1)
				{
					special_price+=grid[buggage.get(j).get(0)][index];
				}
				else
				{
					return false;
				}
			}
		}
		return true;
	}

}
